#include "mynes.h"
#include "main.h"
#include "nofconfig.h"
#include "nofrendo.h"
#include "mynes_config.h"


void *mynes_alloc(int size, bool fast_mem)
{
   if (fast_mem)
   {
      return heap_caps_malloc(size, MALLOC_CAP_8BIT);
      //return os_malloc(size);
   }
   else
   {
      return heap_caps_malloc_prefer(size, MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT);
   }
}
void mynes_free(void *data)
{

    //heap_caps_free(data);
    os_free(data);

}

esp_err_t mynes_init(char *filename)
{  
   //char buf[50];
    mynes_DEBUG("初始化...:%s\r\n",filename);

   //g2u(filename,strlen(filename),buf,50);

   //mynes_DEBUG("初始化2...:%s\r\n",buf);
   
   printf_memory();
   nofrendo_main(0,filename);

    //xTaskCreate(mynes_test_task,"mynes_test_task",1024*10,NULL,2,NULL);

 	return 0;
}

void mynes_test_task(void *pvParameter)
{
	while (1) 
    {

       
    if (gpio_get_level(KEY_3)==0)
    {

      nofrendo_main(0,nes_file_1);
      
    }
    if (gpio_get_level(KEY_4)==0)
    {

       nofrendo_main(0, nes_file_2);
      
    }  


    vTaskDelay(1000 / portTICK_PERIOD_MS); 
 	}
	vTaskDelete(NULL);
}
